package com.spring_event;

import com.spring_event.entity.Cat;
import com.spring_event.entity.Dog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.event.EventListener;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Component;

import java.util.HashMap;

@Component
public class Demo {


	public static void main(String[] args) {
		ApplicationContext app = new ClassPathXmlApplicationContext("applicationContext.xml");

		HashMap<Object, Object> map = new HashMap<>();
		map.put("name","小明");

		Cat cat = new Cat("tom","公");
		EventDemo<Cat> catEventDemo = new EventDemo<>(map, cat);
		app.publishEvent(catEventDemo);

		Dog dog = new Dog("啊黄", "母");
		EventDemo<Dog> dogEventDemo = new EventDemo<>(map, dog);
		app.publishEvent(dogEventDemo);

		System.out.println("发布事件完成");


	}


	@EventListener()
	public void processEventDemo(EventDemo<Cat> event) {
		System.out.println(event.getT());

	}


}
